﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web.Services;
using System.Web.Security;
using System.Collections;
using System.ComponentModel;
using System.Web.Services.Description;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Xml;
using System.IO;
using System.Text;
using System.Transactions;
using WebServiceSmart.Router;
using Thrift.Transport;
using Thrift.Protocol;
using Thrift.Route;
using System.Runtime.InteropServices;
using System.Collections.Generic;
using log4net;
using System.Security.Cryptography;
using System.Net;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Threading;
using WebServiceSmart.Model;
using Microsoft.CSharp;
using System.CodeDom.Compiler;
using System.CodeDom;
using System.Reflection;
namespace WebServiceSmart
{
    public partial class MyService
    {

        //根据手机号码返回用户信息
        //包括用户地址和银行卡信息
        [WebMethod(Description = "基础调用")]
        public string XCX_GetUserByPhone(string msg)
        {
            ILog logJieKou = LogManager.GetLogger("LoggerRecod");
            string logip = Context.Request.ServerVariables.Get("Remote_Addr").ToString();

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            mysqlcli mainsql = new mysqlcli();
            try
            {
                byte[] bytrcv = Convert.FromBase64String(msg);
                ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv);
                if (!comrcv.__isset.byte_Flag)
                {
                    ret.Map_Args["ErrorMsg"] = "解析失败";  //参数错误
                    goto EXIT;
                }
                if (comrcv.Byte_Flag != 1)
                {
                    ret.Map_Args["ErrorMsg"] = "解析失败";  //参数错误
                    goto EXIT;
                }
                logJieKou.Info("New根据手机号码返回用户信息-" + comrcv.Map_Args["phone"]);
                mainsql.openYongHuServicesql();
                int bindcount = comrcv.Byte_Flag;
                if (bindcount == 1)
                {
                    string phone = comrcv.Map_Args["phone"];
                    ret.List_MapArgs = new List<Dictionary<string, string>>();
                    #region 获取主表的数据
                    string sqlcmd = string.Format("SELECT * FROM {0}  where user_phone ='{1}'", BIAOYONGHUUSER, phone);
                    DataTable ds = mainsql.SqlExcuteWithReturn(sqlcmd);
                    if (ds.Rows.Count == 0)
                    {
                        mainsql.closesql();
                        ret.Map_Args["ErrorMsg"] = "找不到此用户";  //参数错误
                        goto EXIT;
                    }
                    ret.Map_Args.Add("1AllCount", ds.Rows.Count.ToString());
                    foreach (DataRow row in ds.Rows)
                    {
                        Dictionary<string, string> newNetImple = new Dictionary<string, string>();
                        foreach (DataColumn dl in ds.Columns)
                        {
                            newNetImple.Add("1" + dl.ColumnName, row[dl.ColumnName].ToString());
                        }
                        ret.List_MapArgs.Add(newNetImple);
                    }
                    #endregion

                    #region 获取地址表的数据
                    sqlcmd = string.Format("SELECT * FROM {0}  where addr_userphone ='{1}'", BIAOYONGHUUSERADDR, phone);
                    ds = mainsql.SqlExcuteWithReturn(sqlcmd);
                    ret.Map_Args.Add("2AllCount", ds.Rows.Count.ToString());
                    if (ds.Rows.Count != 0)
                    {
                        foreach (DataRow row in ds.Rows)
                        {
                            Dictionary<string, string> newNetImple = new Dictionary<string, string>();
                            foreach (DataColumn dl in ds.Columns)
                            {
                                newNetImple.Add("2" + dl.ColumnName, row[dl.ColumnName].ToString());
                            }
                            ret.List_MapArgs.Add(newNetImple);
                        }
                    }
                    #endregion


                    #region 获取银行卡的数据
                    sqlcmd = string.Format("SELECT * FROM {0}  where bc_userphone ='{1}'", BIAOYONGHUUSERBANKCARD, phone);
                    ds = mainsql.SqlExcuteWithReturn(sqlcmd);
                    ret.Map_Args.Add("3AllCount", ds.Rows.Count.ToString());
                    if (ds.Rows.Count != 0)
                    {
                        foreach (DataRow row in ds.Rows)
                        {
                            Dictionary<string, string> newNetImple = new Dictionary<string, string>();
                            foreach (DataColumn dl in ds.Columns)
                            {
                                newNetImple.Add("3" + dl.ColumnName, row[dl.ColumnName].ToString());
                            }
                            ret.List_MapArgs.Add(newNetImple);
                        }
                    }
                    #endregion
                }
                else
                {
                    ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                    goto EXIT;
                }
                ret.Byte_Flag = 1;
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = "调用成功";  //参数错误
            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
            }
            EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }

        //根据电话获取用户地址
        [WebMethod(Description = "基础调用")]
        public string XCX_GetUserAddrByPhone(string msg)
        {
            ILog logJieKou = LogManager.GetLogger("LoggerRecod");
            string logip = Context.Request.ServerVariables.Get("Remote_Addr").ToString();

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            mysqlcli mainsql = new mysqlcli();
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);
            try
            {
                if (!comrcv.__isset.byte_Flag)
                {
                    ret.Map_Args["ErrorMsg"] = "解析失败";  //参数错误
                    goto EXIT;
                }
                if (comrcv.Byte_Flag != 1)
                {
                    ret.Map_Args["ErrorMsg"] = "解析失败";  //参数错误
                    goto EXIT;
                }
                logJieKou.Info("根据电话获取用户地址-" + comrcv.Map_Args["phone"]);
                mainsql.openYongHuServicesql();
                int bindcount = comrcv.Byte_Flag;
                if (bindcount == 1)
                {
                    string phone = comrcv.Map_Args["phone"];
                    ret.List_MapArgs = new List<Dictionary<string, string>>();

                    #region 获取地址表的数据
                    string sqlcmd = string.Format("SELECT * FROM {0}  where addr_userphone ='{1}'", BIAOYONGHUUSERADDR, phone);
                    DataTable ds = mainsql.SqlExcuteWithReturn(sqlcmd);
                    ret.Map_Args.Add("AllCount", ds.Rows.Count.ToString());
                    if (ds.Rows.Count != 0)
                    {
                        foreach (DataRow row in ds.Rows)
                        {
                            Dictionary<string, string> newNetImple = new Dictionary<string, string>();
                            foreach (DataColumn dl in ds.Columns)
                            {
                                newNetImple.Add(dl.ColumnName, row[dl.ColumnName].ToString());
                            }
                            ret.List_MapArgs.Add(newNetImple);
                        }
                    }
                    #endregion
                }
                else
                {
                    ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                    goto EXIT;
                }
                ret.Byte_Flag = 1;
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = "调用成功";  //参数错误
            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
            }
            EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }

        //修改用户地址
        [WebMethod(Description = "基础调用")]
        public string XCX_ChangeUserAddr(string msg)
        {
            ILog logJieKou = LogManager.GetLogger("LoggerRecod");
            string logip = Context.Request.ServerVariables.Get("Remote_Addr").ToString();

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            mysqlcli mainsql = new mysqlcli();
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);
            try
            {
                if (!comrcv.__isset.byte_Flag)
                {
                    ret.Map_Args["ErrorMsg"] = "解析失败";  //参数错误
                    goto EXIT;
                }
                if (comrcv.Byte_Flag != 1)
                {
                    ret.Map_Args["ErrorMsg"] = "解析失败";  //参数错误
                    goto EXIT;
                }
                string Sid = comrcv.Map_Args["Sid"];
                string addr_userphone = comrcv.Map_Args["addr_userphone"];

                string addr_isfrist = comrcv.Map_Args["addr_isfrist"];


                string addr_name = comrcv.Map_Args["addr_name"];
                string addr_addrphone = comrcv.Map_Args["addr_addrphone"];
                string addr_address = comrcv.Map_Args["addr_address"];

                string addr_huoming = comrcv.Map_Args["addr_huoming"];
                string addr_baozhuang = comrcv.Map_Args["addr_baozhuang"];

                string addr_comname = comrcv.Map_Args.ContainsKey("addr_comname") ? comrcv.Map_Args["addr_comname"] : string.Empty;

                string addr_longitude = comrcv.Map_Args["addr_longitude"];
                string addr_latitude = comrcv.Map_Args["addr_latitude"];
                string addr_default = comrcv.Map_Args["addr_default"];

                logJieKou.Info("修改用户地址-" + addr_userphone);
                mainsql.openYongHuServicesql();
                string sqlcmd = string.Format("SELECT * FROM {0}  where Sid ='{1}' AND addr_userphone='{2}';", BIAOYONGHUUSERADDR, Sid, addr_userphone);
                DataTable ds = mainsql.SqlExcuteWithReturn(sqlcmd);
                if (ds.Rows.Count == 0)
                {
                    mainsql.closesql();
                    ret.Map_Args["ErrorMsg"] = "手机号码关联的账号不存在";  //参数错误
                    goto EXIT;
                }

                int sqlret = 0;
                if (addr_isfrist == "1")
                {
                    sqlcmd = string.Format("update {0} set addr_isfrist='0' where addr_userphone='{1}'",
                       BIAOYONGHUUSERADDR, addr_userphone);
                    sqlret = mainsql.SqlExcuteNoReturn(sqlcmd);
                    if (sqlret < 0)
                    {
                        ret.Map_Args["ErrorMsg"] = "修改失败";  //参数错误
                        goto EXIT;
                    }
                }
                else
                {
                    addr_isfrist = "0";
                }

                sqlcmd = string.Format("update {0} set addr_name='{1}',addr_address='{2}',addr_addrphone='{3}',addr_longitude='{4}'," +
                    "addr_latitude='{5}',addr_default='{6}',addr_isfrist='{7}',addr_huoming='{8}',addr_baozhuang='{9}',addr_comname='{10}' where Sid ='{11}'",
                    BIAOYONGHUUSERADDR, addr_name, addr_address, addr_addrphone, addr_longitude, addr_latitude, addr_default, addr_isfrist,
                    addr_huoming, addr_baozhuang, addr_comname, Sid);
                sqlret = mainsql.SqlExcuteNoReturn(sqlcmd);
                if (sqlret != 1)
                {
                    ret.Map_Args["ErrorMsg"] = "修改失败";  //参数错误
                    goto EXIT;
                }

                ret.Byte_Flag = 1;
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = "调用成功";  //参数错误

            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
            }
            EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }

        //新增用户地址
        [WebMethod(Description = "基础调用")]
        public string XCX_AddrUserAddr(string msg)
        {
            ILog logJieKou = LogManager.GetLogger("LoggerRecod");
            string logip = Context.Request.ServerVariables.Get("Remote_Addr").ToString();

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            mysqlcli mainsql = new mysqlcli();
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);
            try
            {
                if (!comrcv.__isset.byte_Flag)
                {
                    ret.Map_Args["ErrorMsg"] = "解析失败";  //参数错误
                    goto EXIT;
                }
                if (comrcv.Byte_Flag != 1)
                {
                    ret.Map_Args["ErrorMsg"] = "解析失败";  //参数错误
                    goto EXIT;
                }
                string addr_userphone = comrcv.Map_Args["addr_userphone"];

                string addr_isfrist = comrcv.Map_Args["addr_isfrist"];

                string addr_comname = comrcv.Map_Args.ContainsKey("addr_comname") ? comrcv.Map_Args["addr_comname"] : string.Empty;


                string addr_name = comrcv.Map_Args["addr_name"];
                string addr_addrphone = comrcv.Map_Args["addr_addrphone"];
                string addr_address = comrcv.Map_Args["addr_address"];

                string addr_huoming = comrcv.Map_Args["addr_huoming"];
                string addr_baozhuang = comrcv.Map_Args["addr_baozhuang"];

                string addr_longitude = comrcv.Map_Args["addr_longitude"];
                string addr_latitude = comrcv.Map_Args["addr_latitude"];
                string addr_default = comrcv.Map_Args["addr_default"];

                logJieKou.Info("新增用户地址-" + addr_userphone);
                mainsql.openYongHuServicesql();
                string sqlcmd = "";
                int sqlret = 0;
                if (addr_isfrist == "1")
                {
                    sqlcmd = string.Format("update {0} set addr_isfrist='0' where addr_userphone='{1}'",
                       BIAOYONGHUUSERADDR, addr_userphone);
                    sqlret = mainsql.SqlExcuteNoReturn(sqlcmd);
                    if (sqlret < 0)
                    {
                        ret.Map_Args["ErrorMsg"] = "修改失败";  //参数错误
                        goto EXIT;
                    }
                }
                sqlcmd = string.Format("INSERT INTO {0} (addr_userphone,addr_name,addr_addrphone,addr_address,addr_longitude," +
                    "addr_latitude,addr_default,addr_isfrist,addr_huoming,addr_baozhuang,addr_comname) " +
                    "VALUES ('{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}')",
                        BIAOYONGHUUSERADDR, addr_userphone, addr_name, addr_addrphone, addr_address, addr_longitude, addr_latitude,
                        addr_default, addr_isfrist, addr_huoming, addr_baozhuang, addr_comname);
                sqlret = mainsql.SqlExcuteNoReturn(sqlcmd);
                if (sqlret != 1)
                {
                    ret.Map_Args["ErrorMsg"] = "修改失败";  //参数错误
                    goto EXIT;
                }

                ret.Byte_Flag = 1;
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = "调用成功";  //参数错误

            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
            }
            EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }

        //删除用户地址
        [WebMethod(Description = "基础调用")]
        public string XCX_DelUserAddr(string msg)
        {
            ILog logJieKou = LogManager.GetLogger("LoggerRecod");
            string logip = Context.Request.ServerVariables.Get("Remote_Addr").ToString();
            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            mysqlcli mainsql = new mysqlcli();
            byte[] bytrcv = Convert.FromBase64String(msg);
            var isjson = true;
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv, ref isjson);
            try
            {
                if (!comrcv.__isset.byte_Flag)
                {
                    ret.Map_Args["ErrorMsg"] = "解析失败";  //参数错误
                    goto EXIT;
                }
                if (comrcv.Byte_Flag != 1)
                {
                    ret.Map_Args["ErrorMsg"] = "解析失败";  //参数错误
                    goto EXIT;
                }
                string Sid = comrcv.Map_Args["Sid"];
                string addr_userphone = comrcv.Map_Args["addr_userphone"];
                logJieKou.Info("删除用户地址-" + addr_userphone);
                mainsql.openYongHuServicesql();
                string sqlcmd = string.Format("delete  from {0} where  Sid ='{1}' AND addr_userphone='{2}' ;",
                    BIAOYONGHUUSERADDR, Sid, addr_userphone);
                int sqlret = mainsql.SqlExcuteNoReturn(sqlcmd);
                if (sqlret != 1)
                {
                    ret.Map_Args["ErrorMsg"] = "删除失败";  //参数错误
                    goto EXIT;
                }
                ret.Byte_Flag = 1;
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = "删除成功";  //参数错误
            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
            }
            EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret, isjson);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }






        //获取用户银行卡信息
        [WebMethod(Description = "基础调用")]
        public string XCX_GetUserBankCard(string msg)
        {
            ILog logJieKou = LogManager.GetLogger("LoggerRecod");
            string logip = Context.Request.ServerVariables.Get("Remote_Addr").ToString();

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            mysqlcli mainsql = new mysqlcli();
            try
            {
                byte[] bytrcv = Convert.FromBase64String(msg);
                ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv);
                if (!comrcv.__isset.byte_Flag)
                {
                    ret.Map_Args["ErrorMsg"] = "解析失败";  //参数错误
                    goto EXIT;
                }
                if (comrcv.Byte_Flag != 1)
                {
                    ret.Map_Args["ErrorMsg"] = "解析失败";  //参数错误
                    goto EXIT;
                }
                logJieKou.Info("获取用户银行卡信息-" + comrcv.Map_Args["userid"]);
                mainsql.openYongHuServicesql();
                int bindcount = comrcv.Byte_Flag;
                if (bindcount == 1)
                {
                    string userid = comrcv.Map_Args["userid"];
                    ret.List_MapArgs = new List<Dictionary<string, string>>();

                    #region 获取地址表的数据
                    string sqlcmd = string.Format("SELECT * FROM {0}  where bc_userid='{1}'", BIAOYONGHUUSERBANKCARD, userid);
                    DataTable ds = mainsql.SqlExcuteWithReturn(sqlcmd);
                    ret.Map_Args.Add("AllCount", ds.Rows.Count.ToString());
                    if (ds.Rows.Count != 0)
                    {
                        foreach (DataRow row in ds.Rows)
                        {
                            Dictionary<string, string> newNetImple = new Dictionary<string, string>();
                            foreach (DataColumn dl in ds.Columns)
                            {
                                newNetImple.Add(dl.ColumnName, row[dl.ColumnName].ToString());
                            }
                            ret.List_MapArgs.Add(newNetImple);
                        }
                    }
                    #endregion
                }
                else
                {
                    ret.Map_Args["ErrorMsg"] = "参数错误";  //参数错误
                    goto EXIT;
                }
                ret.Byte_Flag = 1;
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = "调用成功";  //参数错误
            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
            }
            EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }

        //新增银行卡信息
        [WebMethod(Description = "基础调用")]
        public string XCX_AddrUserBankCard(string msg)
        {
            ILog logJieKou = LogManager.GetLogger("LoggerRecod");
            string logip = Context.Request.ServerVariables.Get("Remote_Addr").ToString();

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            mysqlcli mainsql = new mysqlcli();
            try
            {
                byte[] bytrcv = Convert.FromBase64String(msg);
                ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv);
                if (!comrcv.__isset.byte_Flag)
                {
                    ret.Map_Args["ErrorMsg"] = "解析失败";  //参数错误
                    goto EXIT;
                }
                if (comrcv.Byte_Flag != 1)
                {
                    ret.Map_Args["ErrorMsg"] = "解析失败";  //参数错误
                    goto EXIT;
                }

                string bc_userid = comrcv.Map_Args["bc_userid"];
                string bc_userphone = comrcv.Map_Args["bc_userphone"];

                string bc_username = comrcv.Map_Args["bc_username"];
                string bc_bankname = comrcv.Map_Args["bc_bankname"];
                string bc_bankcardid = comrcv.Map_Args["bc_bankcardid"];
                string bc_bankcardcvv2 = comrcv.Map_Args["bc_bankcardcvv2"];
                string bc_bankcardoverdate = comrcv.Map_Args["bc_bankcardoverdate"];
                string bc_default = comrcv.Map_Args["bc_default"];
                logJieKou.Info("新增银行卡信息-" + bc_userphone);
                mainsql.openYongHuServicesql();
                string sqlcmd = string.Format("INSERT INTO {0} (bc_userid,bc_userphone,bc_username,bc_bankname,bc_bankcardid,bc_bankcardcvv2,bc_bankcardoverdate,bc_default) VALUES ('{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}')",
                        BIAOYONGHUUSERBANKCARD, bc_userid, bc_userphone, bc_username, bc_bankname, bc_bankcardid, bc_bankcardcvv2, bc_bankcardoverdate, bc_default);
                int sqlret = mainsql.SqlExcuteNoReturn(sqlcmd);
                if (sqlret != 1)
                {
                    ret.Map_Args["ErrorMsg"] = "新增失败";  //参数错误
                    goto EXIT;
                }
                ret.Byte_Flag = 1;
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = "调用成功";  //参数错误

            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
            }
            EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }

        //删除用户银行卡信息
        [WebMethod(Description = "基础调用")]
        public string XCX_DelUserBankCard(string msg)
        {
            ILog logJieKou = LogManager.GetLogger("LoggerRecod");
            string logip = Context.Request.ServerVariables.Get("Remote_Addr").ToString();

            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            mysqlcli mainsql = new mysqlcli();
            try
            {
                byte[] bytrcv = Convert.FromBase64String(msg);
                ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv);
                if (!comrcv.__isset.byte_Flag)
                {
                    ret.Map_Args["ErrorMsg"] = "解析失败";  //参数错误
                    goto EXIT;
                }
                if (comrcv.Byte_Flag != 1)
                {
                    ret.Map_Args["ErrorMsg"] = "解析失败";  //参数错误
                    goto EXIT;
                }
                string Sid = comrcv.Map_Args["Sid"];

                logJieKou.Info("删除用户银行卡信息-" + Sid);
                mainsql.openYongHuServicesql();
                string sqlcmd = string.Format("delete  from {0} where  Sid ='{1}' ;",
                    BIAOYONGHUUSERBANKCARD, Sid);
                int sqlret = mainsql.SqlExcuteNoReturn(sqlcmd);
                if (sqlret != 1)
                {
                    ret.Map_Args["ErrorMsg"] = "删除失败";  //参数错误
                    goto EXIT;
                }
                ret.Byte_Flag = 1;
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = "删除成功";  //参数错误
            }
            catch (Exception ex)
            {
                mainsql.closesql();
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
            }
            EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret);
            string retstr = Convert.ToBase64String(retb);
            return retstr;
        }

        //获取相关账务信息，金币，零钱，积分。
        [WebMethod(Description = "正式版本")]
        public string xcx_getuserfinance(string msg)
        {
            ILog logJieKou = LogManager.GetLogger("LoggerZhiFu");
            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv);
            mysqlcli mainsql = new mysqlcli();

            try
            {

                mainsql.openYongHuServicesql();
                string useronlyid = comrcv.Map_Args["userid"];

                CheckUserFinBiao(mainsql, "all", useronlyid);

                logJieKou.Info("获取相关账务信息-" + useronlyid);



                string sqlcmd = string.Format("SELECT *  FROM {0}  where fin_useronlyid='{1}'  ;",
                    BIAOALLFINANCE, useronlyid);
                DataTable ds = mainsql.SqlExcuteWithReturn(sqlcmd);
                ret.Map_Args.Add("AllCount", ds.Rows.Count.ToString());
                ret.List_MapArgs = new List<Dictionary<string, string>>();
                if (ds.Rows.Count != 0)
                {
                    foreach (DataRow row in ds.Rows)
                    {
                        Dictionary<string, string> newNetImple = new Dictionary<string, string>();
                        foreach (DataColumn dl in ds.Columns)
                        {
                            newNetImple.Add(dl.ColumnName, row[dl.ColumnName].ToString());
                        }
                        ret.List_MapArgs.Add(newNetImple);
                    }
                }
                mainsql.closesql();
            }
            catch (Exception ex)
            {
                logJieKou.Info("获取相关账务信息-" + ex.Message);
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                mainsql.closesql();
                goto EXIT;
            }
            ret.Byte_Flag = (sbyte)1;
            EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret);
            string retstr = Convert.ToBase64String(retb);
            return retstr;

        }

        //根据修理厂ID查找修理厂
        [WebMethod(Description = "正式版本")]
        public string GetUserCompanyById(string msg)
        {
            ILog logJieKou = LogManager.GetLogger("LoggerZhiFu");
            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv);
            mysqlcli mainsql = new mysqlcli();

            try
            {
                mainsql.openYongHuServicesql();

                string companyId = comrcv.Map_Args["companyId"];
                //string companyId = "072b3416-d9cf-4a2d-b931-cbcf9572034e";
                string sqlcmd = $"SELECT *  FROM {BIAOUSERCOMPANY} where user_id='{companyId}';";

                var data = mainsql.SqlExcuteWithReturn(sqlcmd).ToModels().FirstOrDefault();

                //ret.Map_Args.Add("AllCount", ds.Rows.Count.ToString());
                //ret.List_MapArgs = new List<Dictionary<string, string>>();
                //if (ds.Rows.Count != 0)
                //{
                //    foreach (DataRow row in ds.Rows)
                //    {
                //        Dictionary<string, string> newNetImple = new Dictionary<string, string>();
                //        foreach (DataColumn dl in ds.Columns)
                //        {
                //            newNetImple.Add(dl.ColumnName, row[dl.ColumnName].ToString());
                //        }
                //        ret.List_MapArgs.Add(newNetImple);
                //    }
                //}

                ret.Map_Args = data;
                mainsql.closesql();
            }
            catch (Exception ex)
            {
                logJieKou.Info("获取修理厂信息-" + ex.Message);
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                mainsql.closesql();
                goto EXIT;
            }
            ret.Byte_Flag = (sbyte)1;
            EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret);
            string retstr = Convert.ToBase64String(retb);
            return retstr;

        }

        //获取修理厂信息
        [WebMethod(Description = "正式版本")]
        public string xcx_getusercompany(string msg)
        {
            ILog logJieKou = LogManager.GetLogger("LoggerZhiFu");
            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv);
            mysqlcli mainsql = new mysqlcli();

            try
            {
                string usercompanyname = comrcv.Map_Args["usercompanyname"];

                string wherestring = "";
                if (usercompanyname != "")
                {
                    wherestring = string.Format(" WHERE user_companyname like '%{0}%' ", usercompanyname);
                }

                logJieKou.Info("获取修理厂信息-" + usercompanyname);

                mainsql.openYongHuServicesql();
                string sqlcmd = string.Format("SELECT *  FROM {0}  {1} ;",
                    BIAOUSERCOMPANY, wherestring);
                DataTable ds = mainsql.SqlExcuteWithReturn(sqlcmd);
                ret.Map_Args.Add("AllCount", ds.Rows.Count.ToString());
                ret.List_MapArgs = new List<Dictionary<string, string>>();
                if (ds.Rows.Count != 0)
                {
                    foreach (DataRow row in ds.Rows)
                    {
                        Dictionary<string, string> newNetImple = new Dictionary<string, string>();
                        foreach (DataColumn dl in ds.Columns)
                        {
                            newNetImple.Add(dl.ColumnName, row[dl.ColumnName].ToString());
                        }
                        ret.List_MapArgs.Add(newNetImple);
                    }
                }
                mainsql.closesql();
            }
            catch (Exception ex)
            {
                logJieKou.Info("获取修理厂信息-" + ex.Message);
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                mainsql.closesql();
                goto EXIT;
            }
            ret.Byte_Flag = (sbyte)1;
            EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret);
            string retstr = Convert.ToBase64String(retb);
            return retstr;

        }

        //使用优惠券信息
        [WebMethod(Description = "正式版本")]
        public string xcx_useuseryhq(string msg)
        {
            ILog logJieKou = LogManager.GetLogger("LoggerZhiFu");
            ComThriftMsg ret = new ComThriftMsg();
            ret.Byte_Flag = (sbyte)-1;
            ret.Map_Args = new Dictionary<string, string>();
            ret.Map_Args.Add("ErrorMsg", "服务器异常");
            byte[] bytrcv = Convert.FromBase64String(msg);
            ComThriftMsg comrcv = CommonTools.Json_ByteTOComThriftAESD(bytrcv);
            mysqlcli mainsql = new mysqlcli();

            try
            {
                string yhqid = comrcv.Map_Args["yhqid"];
                string phone = comrcv.Map_Args["phone"];


                logJieKou.Info("使用优惠券信息-" + yhqid);

                mainsql.openYongHuServicesql();
                string sqlcmd = $"SELECT *  FROM s_coupon  where Sid='{yhqid}' AND coupon_status=0 ";
                var coupon = mainsql.SqlExcuteWithReturn(sqlcmd).ToModels().FirstOrDefault();
                if (coupon == null)
                {
                    ret.Map_Args["ErrorMsg"] = "优惠券信息错误";  //参数错误
                    mainsql.closesql();
                    goto EXIT;
                }

                sqlcmd = $"SELECT *  FROM {BIAOYONGHUUSER}  where user_phone='{phone}';";
                var user = mainsql.SqlExcuteWithReturn(sqlcmd).ToModels().FirstOrDefault();

                if (user == null)
                {
                    ret.Map_Args["ErrorMsg"] = "用户信息错误";  //参数错误
                    mainsql.closesql();
                    goto EXIT;
                }



                mainsql.closesql();
            }
            catch (Exception ex)
            {
                logJieKou.Info("获取优惠券信息-" + ex.Message);
                ret.Map_Args["ErrorMsg"] = ex.Message;  //参数错误
                mainsql.closesql();
                goto EXIT;
            }
            ret.Byte_Flag = (sbyte)1;
            EXIT:
            byte[] retb = CommonTools.Json_ComThriftTOByteAESE(ret);
            string retstr = Convert.ToBase64String(retb);
            return retstr;

        }

    }


}